package com.yin.spring5.service;

import com.yin.spring5.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * AccountService
 *
 * @author Yin Guiqing
 */
@Transactional(propagation = Propagation.REQUIRED,
        isolation = Isolation.DEFAULT)
@Service
public class AccountService {
    final AccountDao accountDao;

    @Autowired
    public AccountService(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    /**
     * 转账业务
     *
     * @param deductId 扣除金额方id
     * @param addId    增加金额方id
     * @param money    转账金额数目
     */
    public void transferAccount(int deductId, int addId, int money) {
        accountDao.deductMoney(deductId, money);
        int i = 10 / 0;
        accountDao.addMoney(addId, money);
    }
}
